<?php
	function upload(){
		$MAX_ALLOWED_SPACE = 50* 1024;
		$up_path = "./data/".basename($_FILES['file']['name']);
		$c = connect();
		$r = mysql_query("SELECT SUM(file_size) FROM articles WHERE owner ='".$_SESSION['idusers']."'");
		$quota = mysql_fetch_array($r)[0] + $_FILES['file']['size'];
		if($quota > $MAX_ALLOWED_SPACE){
			echo "HERE";
			mysql_close($c);
			return false;
		}
		mysql_query("INSERT INTO articles (owner, file_name, file_size, abstract, title) 
			VALUES ('".$_SESSION['idusers']."','".$_FILES['file']['name']."','".$_FILES['file']['size']."','".$_POST['abstract']."','".$_POST['title']."')");
		if(!move_uploaded_file($_FILES['file']['tmp_name'], $up_path))
			echo "Cannot upload file";
		mysql_close($c);
		return true;
	}
?>
